﻿using System.IO;
using Effector.Data;

namespace Effector.ViewModel
{
    /// <summary>
    /// The view model for the directory information class for data binding.
    /// </summary>
    public class DirectoryModel : FileSystemElementModel
    {
        private DirectoryElement _directory;

        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryModel"/> class.
        /// </summary>
        /// <param name="elem">The elem.</param>
        /// <param name="parent">The parent.</param>
        public DirectoryModel(DirectoryElement elem, FileSystemElementModel parent)
            : base(parent)
        {
            _directory = elem;
        }

        /// <summary>
        /// Gets the name of the directory.
        /// </summary>
        /// <value>The name of the directory.</value>
        public string DirectoryName
        {
            get { return _directory.Name; }
        }

        /// <summary>
        /// Loads the children.
        /// </summary>
        protected override void LoadChildren()
        {
            DirectoryInfo[] subdirs = this._directory.Directory.GetDirectories();
            foreach (DirectoryInfo di in subdirs)
            {
                DirectoryElement delem = new DirectoryElement(di);
                DirectoryModel dm = new DirectoryModel(delem, this);
                this.Children.Add(dm as DirectoryModel);
            }
        }

        /// <summary>
        /// Gets the selected.
        /// </summary>
        /// <param name="selectedvalue">The selectedvalue.</param>
        public override void GetSelected(out string selectedvalue)
        {
            selectedvalue = this._directory.Path;
        }
    }
}
